package com.chis.jxc;

import com.chis.jmdatatimer.comm.TxMgmtModule;
import com.chis.jxc.bean.BactBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @Description 查找hbase疫苗流转批号表中多余垃圾的数据，用于清理使用
 * @Company zwx
 * @author wlj
 * @version 2019年08月29日
 */
public class FindTracebat {

    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring.xml"});
        context.start();
        TxMgmtModule txMgmtModule = (TxMgmtModule) context.getBean("TxMgmtModule");
        List<BactBean> list = null;
        list = txMgmtModule.findbact(3200000000L,3201000000L);
        deal(list);
        list = txMgmtModule.findbact(3201000000L,3202000000L);
        deal(list);
        list = txMgmtModule.findbact(3202000000L,3203000000L);
        deal(list);
        list = txMgmtModule.findbact(3203000000L,3204000000L);
        deal(list);
        list = txMgmtModule.findbact(3204000000L,3205000000L);
        deal(list);
        list = txMgmtModule.findbact(3205000000L,3206000000L);
        deal(list);
        list = txMgmtModule.findbact(3206000000L,3207000000L);
        deal(list);
        list = txMgmtModule.findbact(3207000000L,3208000000L);
        deal(list);
        list = txMgmtModule.findbact(3208000000L,3209000000L);
        deal(list);
        list = txMgmtModule.findbact(3209000000L,3210000000L);
        deal(list);
        list = txMgmtModule.findbact(3210000000L,3211000000L);
        deal(list);
        list = txMgmtModule.findbact(3211000000L,3212000000L);
        deal(list);
        list = txMgmtModule.findbact(3212000000L,3213000000L);
        deal(list);
        list = txMgmtModule.findbact(3213000000L,3214000000L);
        deal(list);

    }

    //去除的批号
    public static void deal2(List<BactBean> list){
        if(list != null && list.size() > 0){
            Map<String,Map<String,List<String>>> map = new HashMap<>();
            for(BactBean bactBean : list){
                Map<String,List<String>> map1 = new HashMap<>();
                if(map.containsKey(bactBean.getZonegb())){
                    map1 = map.get(bactBean.getZonegb());
                }
                List<String> list1 = new ArrayList<>();
                if(map1.containsKey(bactBean.getMetarial())){
                    list1 = map1.get(bactBean.getMetarial());
                }
                list1.add(bactBean.getBatnmb());
                map1.put(bactBean.getMetarial(),list1);
                map.put(bactBean.getZonegb(),map1);
            }
            for(String zonegb : map.keySet()){
                System.out.println("地区："+zonegb);
                Map<String,List<String>> map1 = map.get(zonegb);
                for(String matecode : map1.keySet()){
                    List<String> list1 = map1.get(matecode);
                    Map<String,List<String>> tmp = new HashMap<>();
                    for(String s : list1){
                        List<String> l1 = new ArrayList<>();
                        if(tmp.containsKey(s.trim().toLowerCase())){
                            l1 = tmp.get(s.trim().toLowerCase());
                        }
                        l1.add(s);
                        tmp.put(s.trim().toLowerCase(),l1);
                    }
                    StringBuilder sb = new StringBuilder();
                    for(String core : tmp.keySet()){
                        List<String> l = tmp.get(core);
                        if(l.size() > 1){
                            for(String s : l){
                                if(!s.equals(core)){
                                    sb.append(",").append(s);
                                }
                            }
                        }
                    }

                    System.out.println("疫苗："+matecode+" 批号："+sb.substring(1));
                }

            }
        }

    }

    //打印所有地区流转表批号
    public static void deal(List<BactBean> list){
        if(list != null && list.size() > 0){
            Map<String,Map<String,List<String>>> map = new HashMap<>();
            for(BactBean bactBean : list){
                Map<String,List<String>> map1 = new HashMap<>();
                if(map.containsKey(bactBean.getZonegb())){
                    map1 = map.get(bactBean.getZonegb());
                }
                List<String> list1 = new ArrayList<>();
                if(map1.containsKey(bactBean.getMetarial())){
                    list1 = map1.get(bactBean.getMetarial());
                }
                list1.add(bactBean.getBatnmb());
                map1.put(bactBean.getMetarial(),list1);
                map.put(bactBean.getZonegb(),map1);
            }
            for(String zonegb : map.keySet()){
                System.out.println("地区："+zonegb);
                Map<String,List<String>> map1 = map.get(zonegb);
                for(String matecode : map1.keySet()){
                    List<String> list1 = map1.get(matecode);
                    StringBuilder sb = new StringBuilder();
                    for(String s : list1){
                        sb.append(",").append(s);
                    }
                    System.out.println("疫苗："+matecode+" 批号："+sb.toString());
                }

            }
        }

    }

}
